#ifndef _UTILITY_H_
#define _UTILITY_H_
#pragma warning (disable:4251)
#include <cocos2d.h>
#include <boost/function.hpp>
#include "typedef.h"
using namespace cocos2d;

#ifdef WIN32
#define snprintf _snprintf
#endif

#define CCR(x, y, width, height) CCRect(float(x), float(y), float(width), float(height))
#define CCS(width, height) CCSize(float(width), float(height))
#define CCP(x,y) CCPoint(float(x),float(y))

int SplitLine(char **templa, int templatecount, char *pkt,char space);

template <typename Type>
class CAutoDel
{
public:
	CAutoDel(Type *data)
	{
		m_pData = data;
	}
	~CAutoDel()
	{
		delete m_pData;
	}
private:
	Type *m_pData;
};

int Random(int min,int max);

typedef boost::function<void(CCTexture2D*)> OnAddImageFun;
void AddImageToCache(const char *path,OnAddImageFun fun);
CCTexture2D *AddImageToCache(const char *path);
void RemoveTexture(CCTexture2D*);

void SetScale(float);
float GetScale();

float GetFrameStep();
void GetFrameStep(SPoint &src,SPoint &target,float &x,float &y,EDirect &direct);
void GetSpeed(CCPoint &src,CCPoint &target,float &x,float &y,EDirect &direct);

CCAnimate *CreateAnimate(CCTexture2D *pTexture,int frameNum,float dt);
CCSpriteFrame *GetAniFrame(CCAnimate *pAni,uint32 frame);

bool InRect(CCPoint &pos,CCRect &rect);

template<typename Type>
inline Type RandSelect(Type *arr,int num)
{
    return arr[Random(0,num-1)];
}

#endif